using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace AzureContrib.WindowsAzure.StorageClient
{
	internal class CloudTableClientWrapper : ICloudTableClient
	{
		private CloudTableClient cloudTableClient;

		public CloudTableClientWrapper(Uri tableBaseAddress, IStorageCredentials credentials)
		{
			cloudTableClient = new CloudTableClient(tableBaseAddress.AbsoluteUri, credentials.UnWrap());
		}

		public DateTime MinSupportedDateTime
		{
			get { return cloudTableClient.MinSupportedDateTime; }
		}

		public Uri BaseUri
		{
			get { return cloudTableClient.BaseUri; }
		}

		public RetryPolicy RetryPolicy
		{
			get { return cloudTableClient.RetryPolicy; }
			set { cloudTableClient.RetryPolicy = value; }
		}

		public TimeSpan Timeout
		{
			get { return cloudTableClient.Timeout; }
			set { cloudTableClient.Timeout = value; }
		}

		public StorageCredentials Credentials
		{
			get { return cloudTableClient.Credentials; }
		}

		public void CreateTablesFromModel(Type serviceContextType)
		{
			CloudTableClient.CreateTablesFromModel(serviceContextType, cloudTableClient.BaseUri.AbsoluteUri, cloudTableClient.Credentials);
		}

		public TableServiceContext GetDataServiceContext()
		{
			return cloudTableClient.GetDataServiceContext();
		}

		public void Attach(DataServiceContext serviceContext)
		{
			cloudTableClient.Attach(serviceContext);
		}

		public IAsyncResult BeginCreateTable(string tableName, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginCreateTable(tableName, callback, state);
		}

		public void EndCreateTable(IAsyncResult asyncResult)
		{
			cloudTableClient.EndCreateTable(asyncResult);
		}

		public void CreateTable(string tableName)
		{
			cloudTableClient.CreateTable(tableName);
		}

		public IAsyncResult BeginCreateTableIfNotExist(string tableName, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginCreateTableIfNotExist(tableName, callback, state);
		}

		public bool EndCreateTableIfNotExist(IAsyncResult asyncResult)
		{
			return cloudTableClient.EndCreateTableIfNotExist(asyncResult);
		}

		public bool CreateTableIfNotExist(string tableName)
		{
			return cloudTableClient.CreateTableIfNotExist(tableName);
		}

		public IAsyncResult BeginDoesTableExist(string tableName, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginDoesTableExist(tableName, callback, state);
		}

		public bool EndDoesTableExist(IAsyncResult asyncResult)
		{
			return cloudTableClient.EndDoesTableExist(asyncResult);
		}

		public bool DoesTableExist(string tableName)
		{
			return cloudTableClient.DoesTableExist(tableName);
		}

		public IEnumerable<string> ListTables()
		{
			return cloudTableClient.ListTables();
		}

		public IEnumerable<string> ListTables(string prefix)
		{
			return cloudTableClient.ListTables(prefix);
		}

		public ResultSegment<string> ListTablesSegmented()
		{
			return cloudTableClient.ListTablesSegmented();
		}

		public ResultSegment<string> ListTablesSegmented(int maxResults, ResultContinuation continuationToken)
		{
			return cloudTableClient.ListTablesSegmented(maxResults, continuationToken);
		}

		public ResultSegment<string> ListTablesSegmented(string prefix, int maxResults, ResultContinuation continuationToken)
		{
			return cloudTableClient.ListTablesSegmented(prefix, maxResults, continuationToken);
		}

		public IAsyncResult BeginListTablesSegmented(AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginListTablesSegmented(callback, state);
		}

		public IAsyncResult BeginListTablesSegmented(string prefix, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginListTablesSegmented(prefix, callback, state);
		}

		public IAsyncResult BeginListTablesSegmented(string prefix, int maxResults, ResultContinuation continuationToken, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginListTablesSegmented(prefix, maxResults, continuationToken, callback, state);
		}

		public ResultSegment<string> EndListTablesSegmented(IAsyncResult asyncResult)
		{
			return cloudTableClient.EndListTablesSegmented(asyncResult);
		}

		public IAsyncResult BeginDeleteTable(string tableName, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginDeleteTable(tableName, callback, state);
		}

		public void EndDeleteTable(IAsyncResult asyncResult)
		{
			cloudTableClient.EndDeleteTable(asyncResult);
		}

		public void DeleteTable(string tableName)
		{
			cloudTableClient.DeleteTable(tableName);
		}

		public IAsyncResult BeginDeleteTableIfExist(string tableName, AsyncCallback callback, object state)
		{
			return cloudTableClient.BeginDeleteTableIfExist(tableName, callback, state);
		}

		public bool EndDeleteTableIfExist(IAsyncResult asyncResult)
		{
			return cloudTableClient.EndDeleteTableIfExist(asyncResult);
		}

		public bool DeleteTableIfExist(string tableName)
		{
			return cloudTableClient.DeleteTableIfExist(tableName);
		}
	}
}